fix(openai): 支持 content 前缀思考标签折叠 - #94
Open
Lianye-Scythe wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
部分 OpenAI-compatible API 中转服务不会把推理内容作为独立的
reasoning_content字段返回,而是会将前缀思考块拼接到message.content的开头。标准前缀格式示例:
当前 Lim Code 对原生
reasoning_content已有thought: true支持,但对这种被拼入content的前缀思考块只会按普通 Markdown 文本渲染,导致标签直接暴露,无法折叠为思考过程。修复内容
1. 新增前缀思考标签解析器
新增:
backend/modules/channel/thinkTagParser.ts实现流式安全的前缀思考块解析:
这样可以避免误伤 Markdown / 代码示例中的同类标签。
2. 接入流式响应累加器
修改:
backend/modules/channel/StreamAccumulator.ts在普通文本进入 prompt tool parser 之前,先处理前缀思考块,并将其转换为:
这样前端可以复用现有的思考内容折叠渲染逻辑。
3. 接入 OpenAI 非流式响应解析
修改:
backend/modules/channel/formatters/openai.ts在非流式 OpenAI-compatible 响应中:
message.reasoning_content解析逻辑message.content开头的标准前缀思考块进行拆分4. 补充测试
新增:
backend/__tests__/channel/thinkTagParser.test.ts覆盖:
验证
已本地执行:
通过。
npm test -- backend/__tests__/channel/thinkTagParser.test.ts --runInBand结果:
通过。
影响范围
reasoning_content字段处理兼容性说明
本 PR 有意只处理标准前缀格式:
不会处理以下变体:
这是为了避免误判普通 Markdown / 代码示例。